import jsonpath

d={
    "error_code": 0,
    "stu_info":
    [
        {"id": 223,
         "name": "安妮",
         "sex": "女",
         "classname": "212期",
         "data": {
             "name": "测试1",
             "data": {
                 "name": "测试2"
             }
         }
         },
        {"id": 224,
         "name": "景龙",
         "sex": "男",
         "classname": "212期"
         },
        {"id": 225,
         "name": "MS226",
         "classname": "212期"
         }
    ]
}

# # 通过字典的方式取值，获取第一个学员里的学员名字
# print(d['stu_info'][0]['name'])

# # 模糊匹配  匹配所有学员name
print(jsonpath.jsonpath(d, "$..name"))
# # 匹配第一个学员下面所有的name
# print(jsonpath.jsonpath(d, "$.stu_info[0]..name"))
# #匹配前两个学员的信息
# print(jsonpath.jsonpath(d, "$.stu_info[:2]"))
# # 匹配性别为女的学生信息:
# print(jsonpath.jsonpath(d, "$.stu_info[?(@.sex=='女')]"))
# # 匹配所有包含性别信息的学员信息
# print(jsonpath.jsonpath(d, "$.stu_info[?(@.sex)]"))